<?php ob_start(); session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Quản lý bài viết</title>
<link href="../Twitter_Bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="../CSS/css_admin.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../CSS/validationEngine.jquery.css"/>

<script type="text/javascript" src="../Twitter_Bootstrap/js/jquery.js"></script>
<script type="text/javascript" src="../Twitter_Bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine.js"></script>
<script type="text/javascript" src="../Scripts/jquery.validationEngine-vi.js"></script>
<script type="text/javascript" src="../ckeditor/ckeditor.js"></script> 
<script type="text/javascript" src="../ckfinder/ckfinder.js"></script>
<style type="text/css">
<!--
#tbResult td,#tbResult th
{
	text-align:center;
}
-->
</style>
</head>

<body>
 <?php 
	 include("../Connections/connect_admin.php");
	 ?>
<div class="container" id="Container">
<!--Menu top -->
  <div id="menu">
  	<?php
		include("MainMenu.php");
		$url='../Images/Img_News/';
		$title='';
		$type=0;
		$desc='';
		$image='';
		$content='';
		$ishot=0;
		$isreview=0;
		$id=0;
		$topic=0;
		
		if(isset($_GET["id"]))
		{
			$query="SELECT n.NewsID, n.TopicID,n.NewsType,n.Title,n.Description,n.Image,n.Content,n.IsHot,n.IsReview FROM news n WHERE n.NewsID=".intval($_GET['id']);
			$result=mysql_query($query);
			$row=mysql_fetch_assoc($result);
			$id=$row['NewsID'];
			$title=$row['Title'];
			$type=$row['NewsType'];
			$desc=$row['Description'];
			$image=$row['Image'];
			$content=$row['Content'];
			$ishot=$row['IsHot'];
			$isreview=$row['IsReview'];
			$topic=$row['TopicID'];
		}
	?>
    </div>
  </div>
  <div id="divContain">
  <!--Content -->
   <div class="divTitle"><span class="titlePage" >Viết bài</span></div>
 		<div style="padding-top:30px" >
     <form action="process/News_process.php" method="post" id="formWrite" enctype="multipart/form-data" class="form-horizontal">
        <input type="hidden" id="task" name="task" value="<?php if(isset($_GET["id"])) echo 'update'; else echo 'add'; ?>" />
		 <input type="hidden" id="newsid" name="newsid" value="<?php echo $id; ?>" />
         <input type="hidden" id="image" name="image" value="<?php echo $image; ?>" />
         
		<script type="text/javascript">
        $(function(){
				$("#formWrite").validationEngine();
		});
		</script>
        <table width="100%" border="0" cellspacing="2" cellpadding="2">
 
  	<?php
	if(!isset($_GET["id"]))
	{
		require_once("process/function.php");
		 $urlVNE ="http://vnexpress.net"; 

    $content = MyFunctions::get_content_by_url($urlVNE); 

    $content = MyFunctions::get_content_by_tag($content,"<div id=\"content\">",$urlVNE); 

    $list = MyFunctions::list_all_link($content,$urlVNE);   

	?>
     <tr>
    <td colspan="2">
    Các tin lấy được từ vnexpress.net ngày <script type="text/javascript" src="../Scripts/HienNgayHomNay.js"></script>

    </td>
    </tr>
    <tr>
    	<td></td>
        <td>
       <select id="lienket" name="lienket"> 
      		<option selected="selected" value="">-------- Xin chọn liên kết ---------</option> 
      <?php 

            for ($i=0; $i<count($list); $i++){ 

                                    $class = $list[$i]['class']; 

                                    if($class=="link-folder"){ 

                                                if($i==0){ 

                                                            echo "<optgroup label=\"".$list[$i]['title']."\">\n"; 

                                                }else{ 

                                                            echo "</optgroup><optgroup label=\"".$list[$i]['title']."\">\n";                                

                                                }           

                                    }else if($class!='link-subfolder'){ 

                                                echo "<option value=\"".$list[$i]['href']."\">".$list[$i]['title']."</option>\n"; 

                                    } 

                        } 

                        echo "</optgroup>"; 

            ?>      

    </select>
        </td>
    </tr>
    <?php
	}
	?>
    
    <tr>
    <td>Tiêu đề:</td>
    <td><input type="text" id="txtTitle" name="title" class="validate[required]" style="width:90%" value="<?php echo $title; ?>"   /></td>
  </tr>
  <tr>
    <td>Tóm tắt</td>
    <td><textarea type="text" name="description" id="txtDescription" class="validate[required]" style="width:90%" rows="3" >
    <?php echo $desc; ?>
 		</textarea>
     </td>
  </tr>
  <tr>
    <td>Hình ảnh:</td>
    <td><?php if(isset($_GET['id'])){?><img src="<?php echo $url.$image; ?>" alt="Image" width="150px" /><?php }?>&nbsp;<input type="file" name="updfile" id="updImg" /></td>
  </tr>
   <!--<tr>
    <td>Ảnh nhỏ:</td>
    <td><img src="" alt="" />&nbsp;<input type="file" name="uploadFile" id="updSmallImg" /></td>
  </tr> -->
  <tr>
    <td>Loại tin:</td>
    <td>
    	<select name="type" id="cbxType" style="width:200px">
            <option value="0" <?php if($type==0) echo "checked='checked'"; ?>>Bình thường</option>
            <option value="1" <?php if($type==1) echo "checked='checked'"; ?>>Hình ảnh</option>
            <option value="2" <?php if($type==2) echo "checked='checked'"; ?>>Video</option>
        </select>
    </td>
  </tr>
  <tr>
    <td>Chuyên mục:</td>
    <td>
    	<select name="topic" id="cbxTopic_Search">
    	<option value="0">---Chuyên mục cha---</option>
    	 <?php	  
		function Menu($cap = 0,$gach = '&gt;&gt;  ', $arr = NULL){  
		if(!$arr) $arr = array();//khoi tao 1 array co ten la arr  
		$sql = mysql_query("SELECT * FROM topic WHERE IsDeleted = 0 and IsAllowWriteNews = 1 and ParentID = ".$cap." order by OrderIndex");  
		while($row = mysql_fetch_assoc($sql)){  
		$arr[] = array('id'=>$row['TopicID'],'ten'=>$gach.$row['TopicName']);  
		$arr = Menu($row['TopicID'],$gach.'&gt;&gt;   ',$arr);  
		}  
		return $arr;  
		}  
		$Menu = Menu(0);  

		 foreach($Menu as $k=>$row)
		 {
		 ?>
		 <option value="<?php echo $row["id"]; ?>"<?php if($topic==$row["id"]) echo "selected='selected'"; ?> ><?php echo $row["ten"]; ?></option>
		<?php
		 }
		?>       	
        </select>
    </td>
  </tr>
  <tr>
  	<td></td>
    <td><label class="checkbox"><input type="checkbox" name="ishot" id="isHot" value="ishot" /> Tin nổi bật</label></td>
  </tr>
  <tr>
    <td>Nội dung:</td>
    <td>
    	<textarea name="content" class="validate[required]"><?php echo $content;?> </textarea>
<?php 
	include ("../ckeditor/ckeditor.php");
	include("../ckfinder/ckfinder.php");
	$CKEditor = new CKEditor();
	$CKEditor->basePath = '/ckeditor/';
	CKFinder::SetupCKEditor( $CKEditor, '../ckfinder/' ) ; 
	$CKEditor->replace("content");
?>
    </td>
  </tr>
  <tr>
    <td>Tình trạng duyệt:</td>
    <td class="form-horizontal">
    	<label class="radio"><input type="radio" name="review"  id="chkReviewed" value="reviewed" <?php if($isreview==1) echo "checked='checked'"; ?>  /> Đã duyệt</label>&nbsp;
    	<label class="radio"><input type="radio" name="review" id="chkNoReviewed" value="unreview" <?php if($isreview==0) echo "checked='checked'"; ?>/> Chưa duyệt</label>
    </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" value="Lưu" class="btn btn-primary" />
    &nbsp;<input type="reset" value="Refresh" class="btn btn-success" />
    &nbsp;<a href="News.php" class="btn" >Thoát</a></td>
  </tr>
 
</table>

    </form>
   
    </div>
	</div>
  <!--footer -->
  <div id="footer">
     <?php
     	include("Footer.php");
	 ?>
  </div>
  </div>
  

</body>
</html>

